<?php
/**
 * Jishupu-Laravel-Vue-Admin
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Requests;

use App\Services\AttachmentService;

/**
 * 图集模块表单请求验证
 * Class InfoPictureRequest
 * @package App\Http\Requests
 */
class InfoPictureRequest extends BaseRequest
{
    /**
     * 用户是否有权操作，true是，false否
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 字段验证规则
     *
     * @return array
     */
    public function rules()
    {
        return [
            'info_id' => 'required|integer',
            'image_list_ids' => 'nullable',
            'image_list' => 'nullable',
            'content' => 'nullable'
        ];
    }

    /**
     * 提示信息
     *
     * @return array
     */
    public function messages()
    {
        return [
        ];
    }

    /**
     * 定义场景
     *
     * @var \string[][]
     */
    public $scenes = [
        'store' => ['image_list_ids', 'image_list', 'content'],
        'update' => ['image_list_ids', 'image_list', 'content']
    ];

    /**
     * 验证错误的自定义属性
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'info_id' => __('common.id'),
            'image_list' => __('infoPicture.image_list'),
            'content' => __('common.content'),
        ];
    }


    /**
     * 验证前
     *
     * @return void
     */
    protected function prepareForValidation()
    {
        // 处理图集
        $getRequestPicture = AttachmentService::getRequestPicture($this->image_list);
        $this->offsetSet('image_list_ids', $getRequestPicture['image_list_ids']);
        $this->offsetSet('image_list', $getRequestPicture['image_list']);
    }

}
